package com.cjh.wxdemoserver.base.exception;

import lombok.Getter;

import java.text.MessageFormat;

/**
 * @author ChenJH
 * @description 自定义异常
 */

@Getter
public class BizException extends RuntimeException {
    private final int code;
    private final String msg;

    public BizException(int code, String msg) {
        super("[" + code + "]" + msg);
        this.code = code;
        this.msg = msg;
    }
    public BizException(int code, String msg, Object... args) {
        super("[" + code + "]" + MessageFormat.format(msg, args));
        this.code = code;
        this.msg = MessageFormat.format(msg, args);
        
    }
    public BizException(ResultCode resultCode) {
        super("[" + resultCode.getCode() + "]" + resultCode.getMsg());
        this.code = resultCode.getCode();
        this.msg = resultCode.getMsg();
    }
    public BizException(ResultCode resultCode, Object... args) {
        super("[" + resultCode.getCode() + "]" + MessageFormat.format(resultCode.getMsg(), args));
        this.code = resultCode.getCode();
        this.msg = MessageFormat.format(resultCode.getMsg(), args);
    }
}
